package com.dc.toolkit.hutool.core;

import cn.hutool.core.util.PhoneUtil;
import org.junit.Test;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;

/**
 * Description: Hutool PhoneUtil Demo
 * @author: gdc
 * @date: 2021/4/24
 * @version 1.0
 */
public class PhoneUtilTest {

    String phone = "13112345678";

    /**
     * 测试           是否为手机号
     */
    @Test
    public void testIs(){
        assertThat(PhoneUtil.isMobile(phone), equalTo(true));
        assertThat(PhoneUtil.isPhone(phone), equalTo(true));
        assertThat(PhoneUtil.isMobileHk(phone), equalTo(false));
        assertThat(PhoneUtil.isTel(phone), equalTo(false));
        assertThat(PhoneUtil.isTel400800(phone), equalTo(false));
    }

    /**
     * 测试           截取手机部分信息
     */
    @Test
    public void testSub(){
        assertThat(PhoneUtil.subBefore(phone), equalTo("131"));
        assertThat(PhoneUtil.subBetween(phone), equalTo("1234"));
        assertThat(PhoneUtil.subAfter(phone), equalTo("5678"));
    }

    /**
     * 测试           隐藏手机号部分信息
     */
    @Test
    public void testHide(){
        String hideBefore = (String) PhoneUtil.hideBefore(phone);
        System.out.println(hideBefore);

        String hideBetween = (String) PhoneUtil.hideBetween(phone);
        System.out.println(hideBetween);

        String hideAfter = (String) PhoneUtil.hideAfter(phone);
        System.out.println(hideAfter);
    }
}
